home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / A.D. Software / OOFILE / OOFILE AppMaker / FileAndFind / Pre-built version, as generated / CEditArticle.cp < prev    next >
Text File  |  1995-09-30  |  5KB  |  216 lines

  1. // CEditArticle.cp -- dialog methods
  2. // Created 01/01/95 12:01 PM by AppMaker
  3.  
  4. #include "CEditArticle.h"
  5. #include "FileAndFind_OOFILE.h"
  6.  
  7.  
  8. #include <UReanimator.h>
  9. #include <LStream.h>
  10. #include <LStdControl.h>
  11. #include <LTabGroup.h>
  12. #include <LTextEdit.h>
  13. #include <LListBox.h>
  14. #include <PP_Messages.h>
  15.  
  16. #define PPob_EditArticleID    202
  17. #define RidL_EditArticleID    202
  18.  
  19.  
  20. //----------
  21. //    This is the function you register with URegistrar to create a
  22. //    CEditArticle from a resource
  23. CEditArticle*
  24. CEditArticle::CreateEditArticleStream(
  25.     LStream    *inStream)
  26. {
  27.     return (new CEditArticle(inStream));
  28. }
  29.  
  30. //----------
  31. //    The default constructor does nothing.
  32. CEditArticle::CEditArticle()
  33. {
  34. }
  35.  
  36. //----------
  37. //    The read-from-stream constructor just reads a dialog object.
  38. CEditArticle::CEditArticle(
  39.     LStream    *inStream)
  40.         : LDialogBox(inStream)
  41. {
  42. }
  43.  
  44. //----------
  45. //    The destructor does nothing.
  46. CEditArticle::~CEditArticle()
  47. {
  48. }
  49.  
  50. //----------
  51. //    This member function gets called once the containment hierarchy that contains
  52. //    this pane has been built. It gives us a chance to get data members for
  53. //    interesting subviews, and to do other operations now that our subviews exist.
  54. void
  55. CEditArticle::FinishCreateSelf()
  56. {
  57.     LDialogBox::FinishCreateSelf();
  58.  
  59.     mOKButton = (LStdButton *)FindPaneByID('OK  ');
  60.     mCancelButton = (LStdButton *)FindPaneByID('Canl');
  61.     mTitleField = (LTextEdit *)FindPaneByID('Tit2');
  62.     mSourceField = (LTextEdit *)FindPaneByID('Sou2');
  63.     mAuthorsField = (LTextEdit *)FindPaneByID('Aut2');
  64.     mAbstractField = (LTextEdit *)FindPaneByID('Abs2');
  65.     mLocationsList = (LListBox *)FindPaneByID('Locs');
  66.     mAddLocationButton = (LStdButton *)FindPaneByID('Addn');
  67.     mDelLocationButton = (LStdButton *)FindPaneByID('Deln');
  68.     mGoFirstButton = (LStdButton *)FindPaneByID('GoFt');
  69.     mGoPrevButton = (LStdButton *)FindPaneByID('GoPv');
  70.     mGoNextButton = (LStdButton *)FindPaneByID('GoNt');
  71.     mGoLastButton = (LStdButton *)FindPaneByID('GoLt');
  72.  
  73.     LTabGroup    *tabGroup = new LTabGroup(this);
  74.     mTitleField->SetSuperCommander(tabGroup);    // becomes the active field
  75.     mSourceField->SetSuperCommander(tabGroup);
  76.     mAuthorsField->SetSuperCommander(tabGroup);
  77.     mAbstractField->SetSuperCommander(tabGroup);
  78.  
  79.     UReanimator::LinkListenerToControls(this, this, RidL_EditArticleID);
  80.         // the purpose is to "connect" self to whatever controls
  81.         // that we want to "listen" to
  82.  
  83. // any additional initialization for your dialog:
  84.  
  85. }
  86.  
  87. //----------
  88. void
  89. CEditArticle::DoAddArticleLocation()
  90. {
  91. }
  92.  
  93. //----------
  94. void
  95. CEditArticle::DoDelArticleLocation()
  96. {
  97. }
  98.  
  99. //----------
  100. void
  101. CEditArticle::ListenToMessage(
  102.     MessageT    inMessage,
  103.     void        *ioParam)
  104. {
  105.     switch (inMessage) {
  106. case 'Addn':
  107.         DoAddArticleLocation();
  108.     break;
  109.  
  110. case 'Deln':
  111.         DoDelArticleLocation();
  112.     break;
  113.  
  114.     default:
  115.     if (!OOFILEhandlesMessage(inMessage, ioParam))
  116.       ; // do something
  117.         break;
  118.     }
  119. }
  120.  
  121.  
  122. //----------
  123. Boolean
  124. CEditArticle::ObeyCommand(
  125.     CommandT    inCommand,
  126.     void        *ioParam)
  127. {
  128.     Boolean        cmdHandled = true;
  129.  
  130.     switch (inCommand) {
  131.  
  132.     // +++ Add cases here for the commands you handle
  133.     //        Remember to add same cases to FindCommandStatus below
  134.     //        to enable/disable the commands
  135.  
  136.     default:
  137.     cmdHandled = OOFILEhandlesMessage(inCommand, ioParam);
  138.     if (!cmdHandled)
  139.             cmdHandled = LDialogBox::ObeyCommand(inCommand, ioParam);
  140.         break;
  141.     }
  142.  
  143.     return cmdHandled;
  144. }
  145.  
  146. //----------
  147. void
  148. CEditArticle::FindCommandStatus(
  149.     CommandT    inCommand,
  150.     Boolean        &outEnabled,
  151.     Boolean        &outUsesMark,
  152.     Char16        &outMark,
  153.     Str255        outName)
  154. {
  155.     outUsesMark = false;
  156.  
  157.     switch (inCommand) {
  158.  
  159.     // +++ Add cases here for the commands you handle
  160.  
  161.     default:
  162.             LDialogBox::FindCommandStatus(inCommand, outEnabled,
  163.                                             outUsesMark, outMark, outName);
  164.         break;
  165.     }
  166. }
  167.  
  168. //----------
  169. Boolean
  170. CEditArticle::FocusDraw()
  171. {
  172.     Boolean        focused = LView::FocusDraw();
  173.  
  174.     if (focused) {
  175.         AuxWinHandle    awHndl;
  176.         CTabHandle        awCTable;
  177.         ColorSpec        contentSpec;
  178.  
  179.         GetAuxWin(GetMacPort(), &awHndl);
  180.         awCTable = (**awHndl).awCTable;
  181.         contentSpec = (**awCTable).ctTable [wContentColor];        // should search vs. index
  182.         ::RGBBackColor(&contentSpec.rgb);
  183.     }
  184.  
  185.     return focused;
  186. }
  187.  
  188.  
  189. void CEditArticle::SetDatabase(CdbArticles* inArticles)
  190. {
  191. // our copy of the database, if we need to change its state in our Do methods
  192. mArticles = new CdbArticles(*inArticles);    
  193.  
  194. mMainTable = mArticles;  // mixin dbEditHelper's copy of pointer, which it deletes for us
  195. // link fields to controls created in FinishCreateSelf
  196.     LinkField(mArticles->Title(), mTitleField);
  197.     LinkField(mArticles->Source(), mSourceField);
  198.     LinkField(mArticles->Authors(), mAuthorsField);
  199.     LinkField(mArticles->Abstract(), mAbstractField);
  200. }
  201.  
  202.  
  203. // lightweight class to wrap creating CEditArticle
  204.  
  205. LWindow* CEditArticleFactory::makeWindow(const bool loadData) const
  206. {
  207.    CdbArticles*  realTable = (CdbArticles*) mTable;  // safe downcast
  208.    // would later use dynamic_cast to test the above
  209.    CEditArticle* dlg =  ((CEditArticle *)LWindow::CreateWindow(PPob_EditArticleID, mCommander));
  210.  dlg->SetDatabase(realTable);
  211.    if (loadData)
  212.      dlg->LoadData();  // do separately so SetDatabase doesn't imply updating fields
  213.  return (LWindow*) dlg;
  214. }
  215.  
  216.